﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace intelliSys.Management.Automation.Test
{
    /// <summary>
    /// Interaction logic for ErrorMessage.xaml
    /// </summary>
    public partial class MessagePrompt : Window
    {
        static MessagePrompt errormsg;
        public static void ShutdownWaitingCurrent()
        {
            if ((errormsg.MessageType & MessageType.Wait) == MessageType.Wait)
            {
                errormsg.RestoreWindowStatus();
                errormsg.Close();
                errormsg = null;
            }
        }
        public MessageType MessageType
        {
            get;
            set;
        }
        public static object ShowDialogue(Window sender, string summary)
        {
            errormsg = new MessagePrompt();
            errormsg.ShowInTaskbar = false;
            errormsg.Owner = sender;
            errormsg.Height = (sender).ActualHeight;
            errormsg.Width = (sender).ActualWidth;
            errormsg.Summary.Text = summary;
            errormsg.SetWindowStatus();
            sender.Topmost = true;
            errormsg.ShowDialog();
            string s = errormsg.ContentBox.Text;
            errormsg = null;
            return s;
        }
        private MessagePrompt()
        {
            this.InitializeComponent();
            // Insert code required on object creation below this point.
        }
        public MessageType Result
        {
            get;
            set;
        }
        void RestoreWindowStatus()
        {
            this.Owner.Effect = null;
            this.Owner.Topmost = false;
        }
        void SetWindowStatus()
        {
            (Resources["OnLoaded1"] as System.Windows.Media.Animation.Storyboard).Completed += new EventHandler(ErrorMessage_Completed);
            (Resources["OnLoaded1"] as System.Windows.Media.Animation.Storyboard).Begin();
        }

        void ErrorMessage_Completed(object sender, EventArgs e)
        {
            if (errormsg == null) return;
            Owner.Effect = new System.Windows.Media.Effects.BlurEffect() { Radius = 10 };
        }
        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            Result = MessageType.Cancel;
            RestoreWindowStatus();
            this.Close();
        }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            Result = MessageType.Comfirm;
            RestoreWindowStatus();
            this.Close();
        }
    }

}